package cn.com.bo.util.crypto;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import cn.com.bo.util.io.BytesUtils;

/**
 * 
 * MD5 �����㷨,��ԭ����iOcean.util��Ŀ���ƹ���
 * 
 * <p>
 * detailed comment
 * @author wangqifeng
 * @date 2013 3 6 10:37:58
 * @since
 */
public class MD5Util
{
    private MessageDigest mdInst = null;

    public MD5Util()
    {
        try
        {
            mdInst = MessageDigest.getInstance("MD5");
        }
        catch (NoSuchAlgorithmException e)
        {

        }
    }

    public final byte[] md5(byte[] btInput)
    {
        mdInst.update(btInput);
        return mdInst.digest();
    }

    public final long hash(String s)
    {
        mdInst.update(s.getBytes());
        byte[] bKey = mdInst.digest();
        long res = BytesUtils.byte2Long(bKey, 4);
        return res;

    }

    public final String md5(String s)
    {
        mdInst.update(s.getBytes());
        byte[] md = mdInst.digest();
        return BytesUtils.bytesToHexString(md);
    }

    public static void main(String[] args)
    {
        String s = "7783272485";
        MD5Util util = new MD5Util();
        byte[] b = util.md5(s.getBytes());
        System.out.println(BytesUtils.bytesToHexString(b));
    }

}
